package cn.org.timespace.ons.dao.base.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import cn.org.timespace.ons.dao.TSBaseDAO;
import cn.org.timespace.ons.dao.base.MachineTypeNameValueDao;
import cn.org.timespace.ons.vo.base.MachineTypeNameValue;
import cn.org.timespace.ons.vo.base.MachinesConf;

public class MachineTypeNameValueDaoImpl extends TSBaseDAO implements
		MachineTypeNameValueDao {

	@Override
	public void delete(MachineTypeNameValue persistentInstance) {
		// TODO Auto-generated method stub
		log.debug("deleting MachineTypeNameValue Instance");
		try{
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		}catch(RuntimeException re){
			log.debug("delete fail",re);
			throw re;
		}
	}

	@Override
	public List<MachineTypeNameValue> findByCondition(String id) {
		// TODO Auto-generated method stub
		Session session = null;
		Query query = null;
		List<MachineTypeNameValue> list = new ArrayList();
		
		try{
			StringBuffer queryString = new StringBuffer("from MachineTypeNameValue m where m.theIdMachine ='");
				queryString.append(id);
				queryString.append("'");
				
				
			session = getSessionFactory().openSession();
			query = session.createQuery(queryString.toString());
			
			//MachinesConf machinesConf=null;
			 list=query.list();
		
			
		}catch(RuntimeException re){
			re.printStackTrace();
		}
		return list;
	}

	@Override
	public MachineTypeNameValue findById(String id) {
		// TODO Auto-generated method stub
		log.debug("getting MachineTypeNameValue instance with id: " + id);
		try {
			MachineTypeNameValue instance = (MachineTypeNameValue) getHibernateTemplate().get(
					"cn.org.timespace.ons.vo.base.MachineTypeNameValue", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@Override
	public void save(MachineTypeNameValue transientInstance) {
		// TODO Auto-generated method stub
		log.debug("saving MachineTypeNameValue instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	@Override
	public void update(MachineTypeNameValue instance) {
		// TODO Auto-generated method stub
		try {
			getHibernateTemplate().update(instance);
		} catch (RuntimeException re) {
			log.error("update failed", re);
			throw re;
		}
	}

}
